package cn.wolfcode.luowowo.controller;


import cn.wolfcode.luowowo.domain.StrategyTheme;
import cn.wolfcode.luowowo.query.StrategyThemeQuery;
import cn.wolfcode.luowowo.service.IDestinationService;
import cn.wolfcode.luowowo.service.IStrategyThemeService;
import cn.wolfcode.luowowo.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("strategyTheme")
public class StrategyThemeController {


    @Autowired
    private IStrategyThemeService strategyThemeService;
    @Autowired
    private IDestinationService destinationService;


    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") StrategyThemeQuery qo){

        //看前端页面共享个page
        // pageinfo :是mybatis插件,操作的是mysql数据库
        // Page  : 是spring-data 的组件,操作的是mongodb
        Page<StrategyTheme> page =  strategyThemeService.query(qo);

        model.addAttribute("page",page);
        return "strategyTheme/list";
    }

    // 添加按钮中目的地下拉框:查询所有目的地数据
    @RequestMapping("/listDests")
    @ResponseBody
    public Object listDests(){
        // 查询所有目的地数据(这里不用共享,因为前端发送的是ajax请求,要的是json格式的数据)
        return destinationService.listAll();
    }

    // 添加按钮中保存操作
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(StrategyTheme strategyTheme){
        // 保存和编辑
        strategyThemeService.saveOrUpdate(strategyTheme);
        return JsonResult.success();

    }



}
